set seed 18797

clear
use "cleandata\winprob_matched_dataset60_180"
keep if event=="Rated Bullet game"
xtset game turn
drop if timecontrol_iv
keep if abs(start_eval)<=500





local time=60
local cutoff=9.5
local lbound=3
local ubound=17

gen eval_change=(mover_eval+l.mover_eval)/100
label var eval_change "Change in Stockfish Evaluation"
label var clock "Seconds Remaining"
label var timetaken "Seconds Spent on Move"
binscatter eval_change clock if clock>=`lbound' & clock<=`ubound', rd(`cutoff') discrete linetype(lfit) xtitle("Seconds Remaining") ytitle("Change in Stockfish Evaluation")

graph export "exhibits/eval_beep`time'.pdf", as(pdf) replace

binscatter timetaken clock if clock>=`lbound' & clock<=`ubound', rd(`cutoff') discrete linetype(lfit) xtitle("Seconds Remaining") ytitle("Seconds Spent on Move")
graph export "exhibits/time_beep`time'.pdf", as(pdf) replace

gen dummyoverten=clock>=`cutoff'
reg eval_change c.clock##i.dummyoverten if clock>=`lbound' & clock<=`ubound'
est sto rd`time'
reghdfe eval_change c.clock##i.dummyoverten if clock>=`lbound' & clock<=`ubound', absorb(movercode)
est sto rd`time'_fe

hist clock if clock>=`lbound' & clock<=`ubound', discrete xline(`cutoff', lcolor(gs8) lpattern(dash)) freq fcolor(white) lcolor(dkgreen) ylabel(#3, format(%12.3g))
graph export "exhibits/hist_beep`time'.pdf", as(pdf) replace



forvalues i=1/5{
	summ moverelo if elo_percentile==`i'
	local lowerelo=r(min)
	local upperelo=r(max)

	hist clock if clock>=3 & clock<=17 & elo_percentile==`i', ///
		discrete xline(9.5, lcolor(gs8) lpattern(dash)) freq fcolor(white) lcolor(dkgreen) ylabel(#3, format(%12.3g)) ///
		title("Elo `lowerelo'-`upperelo'") name(elo`i', replace) 
		
	graph export "exhibits/beep_analysis_by_elo`lowerelo'_`upperelo'.pdf", as(pdf) replace
	summ clock if clock==9 & elo_percentile==`i'
	local obs9_`i'=r(N)
	summ clock if clock==10 & elo_percentile==`i'
	local obs10_`i'=r(N)
}

graph combine elo1 elo2 elo3 elo4 elo5, ycommon
graph export "exhibits/beep_analysis_by_elo.pdf", as(pdf) replace

disp `obs10_5'/`obs9_5'
disp `obs10_1'/`obs9_1'

